package com.example.smart_city_0829.activity.sdkm;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.example.smart_city_0829.R;
import com.example.smart_city_0829.adapter.BaseFragmentViewPagerAdapter;
import com.example.smart_city_0829.base.BaseActivity;
import com.google.android.material.tabs.TabItem;
import com.google.android.material.tabs.TabLayout;

import java.util.Arrays;
import java.util.List;

public class XxxdActivity extends BaseActivity {

    private TabLayout tab;
    private TabItem xxls;
    private TabItem xxgy;
    private TabItem xxbj;
    private ViewPager vp;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_xxxd;
    }

    @Override
    protected void initView() {
        tab = (TabLayout) findViewById(R.id.tab);
        xxls = (TabItem) findViewById(R.id.xxls);
        xxgy = (TabItem) findViewById(R.id.xxgy);
        xxbj = (TabItem) findViewById(R.id.xxbj);
        vp = (ViewPager) findViewById(R.id.vp);
    }

    @Override
    protected void initData() {
        List<Fragment> fragments = Arrays.asList(new XxlsFragment(), new XxgyFragment(), new XxbjFragment());
        List<String> strings = Arrays.asList("学习历史", "学习感言", "学习笔记");
        vp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return strings.get(position);
            }
        });
        tab.setupWithViewPager(vp);

    }

    @Override
    protected void initEvent() {
        tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    protected String getActionBarTitle() {
        return "学习心得";
    }
}